import { useEffect, useState, useContext } from "react";
import { ThemeContext } from './ThemeContext'
function Timer() {
    const { theme, toggleTheme, globalState } = useContext(ThemeContext); // 将开辟的ThemeContext通过useContext引入

    const [time, setTime] = useState('')
    useEffect(() => {
        const timerId = setInterval(() => {
            setTime(new Date().toLocaleString())
        }, 1000);
        return () => clearInterval(timerId)
    }, [])
    return <div style={{
        color: theme === 'dark' ? "red" : "blue"
    }}>
        {time}
        <button onClick={toggleTheme}>切换主题</button>
        {globalState}
    </div>
}
export default Timer;